import websock from '~/utils/socket'
import { ElNotification } from 'element-plus'

export const userinit = () => {
  //  用户连接
  websock.onopen('/websocket/system/message', () => {
    //  发送用户ID
    const userinfo: string = localStorage.getItem('saber-userInfo') || ''
    const { content } = JSON.parse(userinfo)
    const params = {
      userId: content.userId
    }
    websock.send(JSON.stringify(params))
    //  接受用户消息
    websock.onmessage((res) => {
      ElNotification({
        title: res.title,
        message: res.content,
        type: 'success',
        position: 'bottom-right'
      })
    })
  })
}
